#pragma once
#include<iostream>
#include<string>
#include<pthread.h>
#include<string>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>
#include <functional>
namespace th{
using func_t = std::function<void(const std::string&)>;
class thread{
     public:
     thread(std::string names,func_t task)
     :name(names),
      func(task),
      state(0)
     {
     }
    static void* aim(void* arg){
        thread *self = static_cast<thread*>(arg);
        self->excute();
        return nullptr;

    }
     bool start(){
       int n= pthread_create(&tid,nullptr,aim,this);
            if(n==0){
                return true;
            }
            else{
            return false;
            }
     }
     bool stop(){
        int n=pthread_cancel(tid);
         if(n==0){
                return true;
            }
            else
            return false;
     }
     void join(){
        pthread_join(tid,nullptr);
     }
    int re_state(){
        return state;
    }
    void excute(){
        state=1;
        func(name);
        state=0;
    }
        private:
        std:: string name;
        pthread_t tid;
        func_t func;
        int state;
};
}